import { observable, action, makeAutoObservable, runInAction } from 'mobx'

class Common {
  constructor() {
    makeAutoObservable(this)
  }

  @observable event$ = null
  @observable eventLog = []

  @action setEvent$(event$) {
    runInAction(() => {
      this.event$ = event$
    })
  }

  @action setEventLog(val, action = 'set') {
    runInAction(() => {
      const { eventLog } = this
      if (action === 'set') {
        if (eventLog.length === 500) {
          eventLog.splice(0, 1)
        }
        eventLog.push(val)
      } else {
        this.eventLog = []
      }
    })
  }
}

export default new Common()
